namespace SimpleWebServices.Web
{
    using System;
    using System.Collections.Specialized;
    using System.Diagnostics.CodeAnalysis;
    using System.Web;

    public sealed class HeaderSuppressionModule : IHttpModule
    {
        public void Dispose()
        {
        }

        public void Init(HttpApplication context)
        {
            if (null == context)
            {
                throw new ArgumentNullException("context");
            }

            context.PreSendRequestHeaders += this.OnPreSendRequestHeaders;
        }

        [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers", Justification = "It is public for testability.")]
        public void OnPreSendRequestHeaders(object sender, EventArgs e)
        {
            NameValueCollection headers = HttpContextFactory.Current.Response.Headers;
            headers.Remove("Server");
            headers.Remove("X-AspNetMvc-Version");
            headers.Remove("X-AspNet-Version");
        }
    }
}